package aaa;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import spirit1.EX01_Sungjukvo;
import spirit1.EX01_sungjukDAO;

public class J26_SungJukNewData extends JDialog {
	private EX01_sungjukDAO sdao = new EX01_sungjukDAO();
	private final JPanel contentPanel = new JPanel();
	private JTextField namet;
	private JTextField kort;
	private JTextField engt;
	private JTextField matt;

	

	
	public J26_SungJukNewData(JFrame p) {
		super(p);
		setBounds(100, 100, 640, 480);
		setTitle("새로운 성적 입력");
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		GridBagLayout gbl_contentPanel = new GridBagLayout();
		gbl_contentPanel.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 50, 0, 50, 0};
		gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		gbl_contentPanel.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		contentPanel.setLayout(gbl_contentPanel);
		{
			JLabel up = new JLabel("New label");
			GridBagConstraints gbc_up = new GridBagConstraints();
			gbc_up.anchor = GridBagConstraints.WEST;
			gbc_up.insets = new Insets(0, 0, 5, 5);
			gbc_up.gridx = 5;
			gbc_up.gridy = 2;
			contentPanel.add(up, gbc_up);
		}
		{
			JLabel name = new JLabel("이름");
			GridBagConstraints gbc_name = new GridBagConstraints();
			gbc_name.insets = new Insets(0, 0, 5, 5);
			gbc_name.gridx = 3;
			gbc_name.gridy = 5;
			contentPanel.add(name, gbc_name);
		}
		{
			namet = new JTextField();
			GridBagConstraints gbc_namet = new GridBagConstraints();
			gbc_namet.insets = new Insets(0, 0, 5, 5);
			gbc_namet.fill = GridBagConstraints.HORIZONTAL;
			gbc_namet.gridx = 6;
			gbc_namet.gridy = 5;
			contentPanel.add(namet, gbc_namet);
			namet.setColumns(10);
		}
		{
			JLabel kor = new JLabel("국어");
			GridBagConstraints gbc_kor = new GridBagConstraints();
			gbc_kor.insets = new Insets(0, 0, 5, 5);
			gbc_kor.gridx = 3;
			gbc_kor.gridy = 7;
			contentPanel.add(kor, gbc_kor);
		}
		{
			kort = new JTextField();
			GridBagConstraints gbc_kort = new GridBagConstraints();
			gbc_kort.insets = new Insets(0, 0, 5, 5);
			gbc_kort.fill = GridBagConstraints.HORIZONTAL;
			gbc_kort.gridx = 6;
			gbc_kort.gridy = 7;
			contentPanel.add(kort, gbc_kort);
			kort.setColumns(10);
		}
		{
			JLabel eng = new JLabel("영어");
			GridBagConstraints gbc_eng = new GridBagConstraints();
			gbc_eng.insets = new Insets(0, 0, 5, 5);
			gbc_eng.gridx = 3;
			gbc_eng.gridy = 9;
			contentPanel.add(eng, gbc_eng);
		}
		{
			engt = new JTextField();
			GridBagConstraints gbc_engt = new GridBagConstraints();
			gbc_engt.insets = new Insets(0, 0, 5, 5);
			gbc_engt.fill = GridBagConstraints.HORIZONTAL;
			gbc_engt.gridx = 6;
			gbc_engt.gridy = 9;
			contentPanel.add(engt, gbc_engt);
			engt.setColumns(10);
		}
		{
			JLabel mat = new JLabel("수학");
			GridBagConstraints gbc_mat = new GridBagConstraints();
			gbc_mat.insets = new Insets(0, 0, 0, 5);
			gbc_mat.gridx = 3;
			gbc_mat.gridy = 11;
			contentPanel.add(mat, gbc_mat);
		}
		{
			matt = new JTextField();
			GridBagConstraints gbc_matt = new GridBagConstraints();
			gbc_matt.insets = new Insets(0, 0, 0, 5);
			gbc_matt.fill = GridBagConstraints.HORIZONTAL;
			gbc_matt.gridx = 6;
			gbc_matt.gridy = 11;
			contentPanel.add(matt, gbc_matt);
			matt.setColumns(10);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						EX01_Sungjukvo ac = new EX01_Sungjukvo();
						JOptionPane.showMessageDialog(null, kort.getText());
						ac.setName(namet.getText());
						ac.setKor(Integer.parseInt(kort.getText()));
						ac.setEng(Integer.parseInt(engt.getText()));
						ac.setMat(Integer.parseInt(matt.getText()));
						if(ac.insertSungjuk(ac))
						JOptionPane.showInputDialog(sdao, "입력성공");
						else
							JOptionPane.showInputDialog(sdao, "실패");
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
			setVisible(true);
		}
	}

}
